import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../components/Home.vue'
import Index from '../components/Index.vue'
import TrainingTask from '../components/task/TrainingTask.vue'
import TestTask from '../components/task/TestTask.vue'
import ReportTask from '../components/task/ReportTask.vue'
import TaskGroup from '../components/task/TaskGroup.vue'
import TrainingRecord from '../components/task/TrainingRecord.vue'
import TestRecord from '../components/task/TestRecord.vue'
import ReportRecord from '../components/task/ReportRecord.vue'
import Login from '../components/Login.vue'
import DataUpload from '../components/data/DataUpload.vue'
import ModelUpload from '../components/model/ModelUpload.vue'
import DataControl from '../components/data/DataControl.vue'
import ModelControl from '../components/model/ModelControl.vue'
Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    { path: '/', redirect: '/login' },
    {
      path: '/home',
      component: Home,
      redirect: '/Index',
      children: [
        { path: '/index', component: Index },
        { path: '/training-task', component: TrainingTask ,},
        { path: '/test-task', component: TestTask },
        { path: '/report-task', component: ReportTask },
        { path: '/task-group', component: TaskGroup },
        { path: '/training-record', component: TrainingRecord },
        { path: '/test-record', component: TestRecord },
        { path: '/report-record', component: ReportRecord },
        { path: '/data-upload',component:DataUpload},
        { path: '/data-control',component:DataControl},
        { path: '/model-upload', component: ModelUpload},
        { path: '/model-control',component:ModelControl}
      ]
    },{
      path:'/login',component:Login
    },
  ]
})
router.beforeEach((to,from,next)=>{
  if(to.path ==='/login'){
    next()
  }else{
    const tokenStr = window.sessionStorage.getItem('token')
    if(!tokenStr){
      next('/login')
    }else{
      next()
    }
  }
})

export default router
